package tool

import (
	"fmt"
	"strconv"
)

//保存切片:[列名:[数据类型:值]...]
func Dprocess2(cols, rows [][]string) (m []map[string]map[string]string) {
	for j := 3; j < len(rows); j++ {
		var m1 = make(map[string]map[string]string)
		for i := 0; i < len(cols); i++ {
			var m2 = make(map[string]string)
			m2[rows[2][i]] = rows[j][i]
			m1[rows[1][i]] = m2
		}
		m = append(m, m1)
	}
	return m
}

//读取切片:[列名:[数据类型:值]...]
func Dprocess2Re(m map[string]map[string]string) (re map[string]interface{}, err error) {
	re = make(map[string]interface{})
	for k, v := range m {
		for t, v2 := range v {
			switch {
			case t == "string":
				re[k] = v2
			case t == "int":
				res, err := strconv.Atoi(v2)
				if err != nil {
					return nil, err
				}
				re[k] = res
			case t == "float64":
				res, err := strconv.ParseFloat(v2, 64)
				if err != nil {
					return nil, err
				}
				re[k] = res
			case t == "float64":
				res, err := strconv.ParseBool(v2)
				if err != nil {
					return nil, err
				}
				re[k] = res
			case t == "array":
				re[k], err = StoInts(v2)
				if err != nil {
					return nil, err
				}
			default:
				err = fmt.Errorf("数据类型不匹配")
				return nil, err
			}
		}
	}
	return
}
